
import { Config } from '../../utils/config.js';
import { Fenxiao } from './fenxiao-model.js';
var fenxiao = new Fenxiao();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    currentStatus: 0,
    page: 1,
    hiddenNomore: true,
    hiddenLoading: true,
    hiddenNullData: true,
    onLoading: false,
    nomore: false,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this._getData();
  },
  /*获取卡券列表*/
  _getData: function () {
    var that = this;
    var args = {
      page: this.data.page,
      number: 10,
      search_type: that.data.currentStatus,
    }
    that.setData({
      hiddenLoading: false
    })
    fenxiao.myCards(that.data.currentTpye, args, (res) => {
      if (that.data.page == 1) {
        that.data.cards = [];
      }
      var items = res.items;
      var cards = that.data.cards.concat(items);
      that.setData({
        cards
      })
      //隐藏正在加载中
      that.setData({
        hiddenLoading: true
      })
      if (items.length == 0) {
        //显示没有数据
        that.setData({
          hiddenNullData: false
        })
      }
      if (that.data.page >= res._meta.pageCount) {
        that.data.nomore = true;
        if (that.data.page > 1) {
          //显示没有更多
          that.setData({
            hiddenNomore: false
          })
        }
      }
    });
  },
  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },
  goTodetails: function (event) {
    var status = order.getDataSet(event, 'status');
    var id = order.getDataSet(event, 'id');
    wx.navigateTo({
      url: 'details?id=' + id + '&status=' + status,
    })
  }

})